/**
 * CodeMsg.java 
 * Copyright © 2014-2016, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2015年6月2日
 */
package com.pshare.enums;

import java.util.HashMap;
import java.util.Map;

import com.pshare.constant.SeaxConstants;

/**
 * 错误信息code-message定义
 */
public enum CodeMsg {

	
	UNSUPPORTMEDIATYPE(415, "请求格式不支持", "unsupported media type"),
	
	SYSTEM_ERROR(500, "系统繁忙，请稍候再试", "system is busy now, please try again later"),
	
	BIZ_ERROR(600, "系统异常", "system error"),
	BIZ_WARN(601, "系统警告", "system warning"),
	WRONG_PARAM(602, "参数错误", "wrong parameter"),
	WRONG_SIGN(603, "参数签名验证失败", "wrong signature"),
	DATA_NOT_FOUND(604, "数据不存在", "can not find the data"),  // 查找或操作的数据不存在
	DUPLICATED_VALUE(605, "数据重复", "the data is duplicated"),  // 提交的数据在数据库已存在
	TOO_MANY_RESULT(606, "存在重复数据", "too many result found"),  // 查找唯一数据时，查到了多条
	WRONG_CLIENT(607, "客户端未能识别", "wrong client"),  // 客户端参数未传bizClientType，或冒充的客户端
	SERVICE_NOT_SUPPORT(608, "该服务暂未开放", "this service has not been supported"), // 在既有业务之外的，系统暂不支持的业务，如预定停车场的具体某个车位
	NO_AUTH(609, "请求验证失败", "authorization failed"),
	RENAME_FAILED(610, "设备名格式不正确", "rename failed"),
	LOCK_CODE_ERROR(611, "地锁编号错误", "lock code error"),
	USER_NOT_FOUND(612, "用户不存在", "can not find the user"), 
	USER_CALLBACK_URL_NULL(613, "回调地址为空", "callback url is null"), 
	NO_LOGIN(702, "请登录", "please login"),
	NO_PERMISSION(703, "您没有该操作权限", "you have no permission"),
	LOCKED(704, "您的账号被锁定，请稍后再试", "your account is locked, please try again later"),  // 账号因短时间内输错3次密码，被暂时锁定不能登录
	FREEZED(705, "您的账号被冻结，请联系客服", "your account is freezed"),   // 用户被冻结不能操作
	WRONG_PWD(706, "密码错误", "wrong password"),
	WRONG_PWD_OR_ACCOUNT(707, "账号或密码错误", "wrong password or account"),
	NO_EMAIL(708, "请设置邮箱", "please set your email first"),
	ACCOUNT_NOT_EXIST(709, "该手机号未注册", "the account is not existing"),
	WRONG_CELLPHONE_FORMAT(710, "手机号码格式有误", "the cellphone number is wrong"),
	CELLPHONE_ALREADY_EXIST(711, "该账号已注册", "the cellphone number has already been registered"),
	CELLPHONE_EXIST(712, "该手机号已存在", "the cellphone number  already exists"),

	PARAM_OVER_LIMIT(818, "参数超过限制", ""),
	GATEWAY_OPERA_CONFLICT(819, "正在操作中", ""),
	GATEWAY_OFFLINE(820, "网关当前不在线", ""),
	GATEWAY_PWD_ERROR(821, "解锁密码错误", ""),
	LOCK_OPERA_ERROR(822, "地锁操作失败", ""),
	CAN_NOT_SHARE_SELF(823, "您不能与自己共享设备", "you can not share the device with yourself"),
	GATEWAY_RECEIVE_TIME_OUT(824, "网关响应超时", ""),
	GATEWAY_CODE_CONFLICT(825, "网关下code冲突", ""),
	LOCK_RECEIVE_TIME_OUT(826, "地锁响应超时", ""),
	DEVICE_RETURN_FAILED(827, "设备返回操作失败", ""),
	RETURN_MSG_INCOMPLETE(828, "返回数据不完全", ""),

	PARKING_DEVICE_NOT_EXIST(901, "地锁不存在", "the parking device is not existing"),
	FILE_READ_ERROR(902, "文件读取失败", "")
	
	;
	
	private Integer code;
	private String message;
	private String englishMsg;
	private static Map<Integer, String> cnmap = new HashMap<Integer, String>();
	private static Map<Integer, String> enmap = new HashMap<Integer, String>();
	
	static {
		initMaps();
	}

	private CodeMsg(Integer code, String message, String englishMsg) {
		this.code = code;
		this.message = message;
		this.englishMsg = englishMsg;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getEnglishMsg() {
		return englishMsg;
	}

	public void setEnglishMsg(String englishMsg) {
		this.englishMsg = englishMsg;
	}

	private static void initMaps() {
		for (CodeMsg em : CodeMsg.values()) {
			cnmap.put(em.getCode(), em.getMessage());
			enmap.put(em.getCode(), em.getEnglishMsg());
		}
	}

	public static String getMsg(Integer code, Boolean isEn) {
		String msg = null;
		if (isEn) {
			msg = enmap.get(code);
		} else {
			msg = cnmap.get(code);
		}
		return msg == null ? SeaxConstants.EMPTY : msg;
	}
}
